//
//  BrandCard.swift
//  shop
//
//  Created by chen on 2025/5/18.
//

import SwiftUI
import Kingfisher

struct BrandCard: View {
    
    var item: BrandGoodItem
    
    var body: some View {
        VStack(spacing: 0) {
            KFImage.url(URL(string: item.mainPic))
                   .loadDiskFileSynchronously()
                   .cacheMemoryOnly()
                   .fade(duration: 0.35)
                   .resizable()
                   .frame(width: 150, height: 150)
            
            VStack(alignment: .leading, spacing: 10){
                Text("\(item.dTitle)")
                    .font(.system(size: 14))
                    .foregroundStyle(.black)
                
                HStack(alignment: .lastTextBaseline ,spacing: 2) {
                    Text("券后")
                        .font(.system(size: 14))
                        .foregroundStyle(.red)
                    
                    Text("¥")
                        .font(.system(size: 14))
                        .foregroundStyle(.red)
                    
                    Text("\(item.actualPrice.formatMoney())")
                        .font(.system(size: 20))
                        .foregroundStyle(.red)
                        .bold()
                        .lineLimit(1)
                        .minimumScaleFactor(0.5)
                    
                    Spacer()
                    
                    HStack(spacing: 2) {
                        Text("¥")
                            .strikethrough()
                        Text("\(item.originPrice.formatMoney())")
                            .lineLimit(1)
                            .minimumScaleFactor(0.5)
                            .strikethrough()
                    }
                    .font(.system(size: 14))
                    .foregroundStyle(.gray)
                }
                
                Text("销量：\(item.monthSales)")
                    .font(.system(size: 12))
                    .foregroundStyle(.black.opacity(0.65))
                    .lineLimit(1)
                    .minimumScaleFactor(0.5)
            }
            .padding(.horizontal, 10)
            .padding(.bottom, 10)
            .padding(.top, 8)
        }
        .frame(width: 150, height: 280)
        .background(.white)
        .cornerRadius(10)
        .overlay(
            RoundedRectangle(cornerRadius: 10)
                .stroke(Color.red, lineWidth: 1)
        )
    }
}
